﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using TimKen.DataEntity;

namespace TimKen.BussLogic
{
    /// <summary>
    /// 用户业务逻辑操作类
    /// </summary>
    public class UserAccountManager
    {
        private readonly TimKen.DataAccess.UserAccountDAO dal = new TimKen.DataAccess.UserAccountDAO();
        public UserAccountManager()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string username)
        {
            return dal.Exists(username);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(TimKen.DataEntity.UserAccount model)
        {
            //此处为判断两张表
            if (UserFacade.Exists(model.UserName)) 
            {
                throw new TimKen.DataEntity.CstmException("Exists UserName");
            }
            else
            {
                model.UserName = model.UserName.Trim().ToLower();
                dal.Add(model);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(TimKen.DataEntity.UserAccount model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string UserName,string WhoDelete)
        {

            dal.Delete(UserName,WhoDelete);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TimKen.DataEntity.UserAccount GetModel(string UserName)
        {

            return dal.GetModel(UserName);
        }

 

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
       public DataSet GetUserAccountPageList(int pagesize, int pageindex, string userType, string customerID, string userName,int languageid)
        {
            return dal.GetUserAccountPageList(pagesize, pageindex, userType, customerID, userName,languageid);
        }

        #endregion  成员方法

        #region Role
        /// <summary>
        /// 获取系统用户类型
        /// </summary>
        /// <returns></returns>
       public DataSet GetRoles(int languageid) 
       {
           return dal.GetRoles(languageid);
       }
        #endregion


       #region 检查用户名密码
       public UserS Login(string userName, string password)
       {
           if (string.IsNullOrEmpty(userName.Trim()) || string.IsNullOrEmpty(password.Trim()))
           {
               throw new ArgumentNullException("userName or password");
           }
           userName = userName.ToLower().Trim();
           return dal.Login(userName, password);
       }
       #endregion



       public void UpdateDataSystemActionList(string userName, string actionList)
       {
           dal.Update(userName, actionList);
       }
    }
}
